package com.usian.admin.rabbitmq;


import com.rabbitmq.client.Channel;
import com.usian.admin.service.WemediaNewsAutoScanService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;



@Component
public class RealnameAuthMQ {

    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;
    //监听方法  routingkey
    @RabbitListener(queues = "adminQueue")
    public void authMQ(Integer id, Message message, Channel channel) throws IOException {//传msg接收消息
        channel.basicAck(message.getMessageProperties().getContentLength(),true);
        System.out.println(message.getBody());
        wemediaNewsAutoScanService.autoScanByMediaNewsId(id);//触发自动审核
    }

    /**
     * 监听文章自动审核
     * @param msg
     * @param channel
     * @throws IOException
     */
    @RabbitHandler
    @RabbitListener(queues = "authQueuedelay")
    public void msg(@Payload Message msg, Channel channel) throws IOException {
        String id = new String(msg.getBody());
        // 直接消费
        channel.basicAck(msg.getMessageProperties().getContentLength(),true);
        wemediaNewsAutoScanService.autoScanByMediaNewsId(Integer.parseInt(id));//触发自动审核
    }




}
